﻿package core.image.psd
{
    import flash.utils.*;

    public class Channel extends Object
    {
        public var Id:int = 0;
        public var Length:int = 0;
        public var Data:ByteArray;
        public var ImageCompression:int = 0;
        private var WriteData:ByteArray;

        public function Channel()
        {
            this.Data = new ByteArray();
            this.WriteData = new ByteArray();
            return;
        }// end function

        public static function Load(core.image.psd:Channel:ByteArrayReader) : Channel
        {
            var _loc_2:* = new Channel;
            _loc_2.Id = core.image.psd:Channel.ReadInt16();
            _loc_2.Length = core.image.psd:Channel.ReadInt32();
            return _loc_2;
        }// end function

        public static function LoadPixelData(_local7:ByteArrayReader, _local7:Channel, _local7:PSDFile, _local7:Layer) : void
        {
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:* = _local7.Read(_local7.Length);
            var _loc_10:* = new ByteArrayReader(_loc_9);
            _local7.ImageCompression = _loc_10.ReadInt16();
            switch(_local7.ImageCompression)
            {
                case 0:
                {
                    _local7.Data = _loc_10.Read(_local7.Dimensions.height * _local7.Dimensions.width);
                    break;
                }
                case 1:
                {
                    _loc_5 = [];
                    _loc_6 = 0;
                    while (_loc_6 < _local7.Dimensions.height)
                    {
                        
                        _loc_5[_loc_6] = _loc_10.ReadInt16();
                        _loc_6++;
                    }
                    _loc_7 = 0;
                    while (_loc_7 < _local7.Dimensions.height)
                    {
                        
                        _loc_8 = _loc_7 * _local7.Dimensions.width;
                        ImageHelper.DecodeRleRow(_loc_10, _local7.Data, _local7.Dimensions.height * _local7.Dimensions.width, _loc_8, _local7.Dimensions.width);
                        _loc_7++;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
